﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Xilium.CefGlue;
using Xilium.CefGlue.Platform;
using System.Runtime.InteropServices;

namespace NFinal.Browser
{
    public partial class Browser : Form
    {
       
        public Browser()
        {
            InitializeComponent();
            //this.cefWebBrowser1.StartUrl = "http://www.baidu.com";
        }
        public bool isLock = false;
        private void Form1_Load(object sender, EventArgs e)
        {
            this.cefWebBrowser1.BrowserCreated += CefWebBrowser1_BrowserCreated;
            this.CenterToScreen();
            this.BringToFront();
        }


        private void CefWebBrowser1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.G)
            {
                MessageBox.Show("ctrl+G");
            }
        }

        private void CefWebBrowser1_BrowserCreated(object sender, EventArgs e)
        {
            this.cefWebBrowser1.Browser.GetMainFrame().LoadUrl(Program.url);
        }

        private void Browser_FormClosed(object sender, FormClosedEventArgs e)
        {
            //this.cefWebBrowser1.Browser.GetMainFrame().Dispose();
            //this.cefWebBrowser1.Browser.Dispose();
            this.cefWebBrowser1.Dispose();
            CefRuntime.Shutdown();
        }

        private void btnLock_Click(object sender, EventArgs e)
        {
            if (isLock)
            {
                this.btnLock.Text = "锁定";
            }
            else
            {
                this.btnLock.Text = "解锁";
            }
            isLock = !isLock;
            this.cefWebBrowser1.Enabled =! isLock;

        }

        private void btnMax_Click(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Maximized)
            {
                this.btnMax.Text = "全屏";
                this.WindowState = FormWindowState.Normal;
            }
            else
            {
                this.btnMax.Text = "还原";
                this.FormBorderStyle = FormBorderStyle.None;
                this.WindowState = FormWindowState.Maximized;
            }
        }
        Point downPoint;
        private void button1_MouseDown(object sender, MouseEventArgs e)
        {
            
        }

        private void button1_MouseMove(object sender, MouseEventArgs e)
        {
            
        }

        private void Browser_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.G)
            {
                MessageBox.Show("G");
            }
        }
        [DllImport("user32", CharSet = CharSet.Auto)]
        public static extern int EnableWindow(IntPtr hwnd, bool bEnable);
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            downPoint = new Point(e.X, e.Y);
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Location = new Point(this.Location.X + e.X - downPoint.X,
                    this.Location.Y + e.Y - downPoint.Y);
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
